package org.jeecg.modules.kuner.curriculumvitaebase.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.common.constant.CommonConstant;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.Strings;
import org.jeecg.modules.kuner.browsebase.service.IKrBrowseBaseService;
import org.jeecg.modules.kuner.collectionbase.service.IKrCollectionBaseService;
import org.jeecg.modules.kuner.curriculumvitaebase.entity.KrCurriculumVitaeBase;
import org.jeecg.modules.kuner.curriculumvitaebase.mapper.KrCurriculumVitaeBaseMapper;
import org.jeecg.modules.kuner.curriculumvitaebase.service.IKrCurriculumVitaeBaseService;
import org.jeecg.modules.kuner.curriculumvitaebase.vo.CurriculumVitaeDetailVO;
import org.jeecg.modules.kuner.curriculumvitaebase.vo.CurriculumVitaeVO;
import org.jeecg.modules.kuner.hirebase.vo.KrHireVO;
import org.jeecg.modules.putil.KrStatic;
import org.jeecg.modules.putil.LoginUserUtil;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * @Description: 个人简历
 * @Author: jeecg-boot
 * @Date: 2025-02-18
 * @Version: V1.0
 */
@Service
public class KrCurriculumVitaeBaseServiceImpl extends ServiceImpl<KrCurriculumVitaeBaseMapper, KrCurriculumVitaeBase> implements IKrCurriculumVitaeBaseService {

    @Resource
    private IKrCollectionBaseService collectionBaseService;
    @Resource
    private LoginUserUtil loginUserUtil;
    @Resource
    private IKrBrowseBaseService browseBaseService;

    /**
     * 混合查询
     *
     * @param mixSearch  搜索条件
     * @param money      薪水上线
     * @param searchType 查询类型
     * @param type       简历分类
     * @param edu        学历下线
     * @param workCity   期望工作城市
     * @param pageNo     分页页码
     * @param pageSize   分页大小
     * @return 查询结果
     */
    @Override
    public IPage<CurriculumVitaeVO> mixSearch(String mixSearch, BigDecimal money, KrStatic.SearchType searchType, String type, Integer edu, String workCity, Integer pageNo, Integer pageSize) {
        IPage<CurriculumVitaeVO> page = new Page<>(pageNo, pageSize);
        switch (searchType) {
            case MONEY:
                page = this.baseMapper.selectOrderByMoney(page, mixSearch, money, type, edu, workCity);
                break;
            default:
                page = this.baseMapper.selectOrderByCreateTime(page, mixSearch, money, type, edu, workCity);
        }
        return page;
    }

    /**
     * 查询简历详情
     *
     * @param id 简历ID
     * @return 查询结果
     */
    @Override
    public CurriculumVitaeDetailVO detail(String id) {
        browseBaseService.visitContent(id, CommonConstant.VISIT_TYPE_JL, CommonConstant.TIME_MODIFY_DECREASE_JL);
        return this.baseMapper.detail(id);
    }

    /**
     * 收藏简历
     *
     * @param curriculumId 被收藏的简历ID
     */
    @Override
    public void doCollection(String curriculumId) {
        getOptById(curriculumId).orElseThrow(() -> new JeecgBootException("找不到对应的简历信息！"));
        collectionBaseService.collection(loginUserUtil.getLoginUser().getId(), curriculumId, KrStatic.ContentType.CURRICULUM_VITAE);
    }

    /**
     * 取消收藏简历
     *
     * @param curriculumId 被取消的简历
     */
    @Override
    public void cancelCollection(String curriculumId) {
        collectionBaseService.unCollection(loginUserUtil.getLoginUser().getId(), curriculumId, KrStatic.ContentType.CURRICULUM_VITAE);
    }

    /**
     * 修改我的简历信息
     *
     * @param curriculumVitaeBase 被修改的简历信息
     */
    @Override
    public void modifyMyCurriculum(KrCurriculumVitaeBase curriculumVitaeBase) {
        String id = curriculumVitaeBase.getId();
        if (Strings.isNotBlank(id)) {
            updateById(curriculumVitaeBase);
        } else {
            curriculumVitaeBase.setPublishUser(loginUserUtil.getLoginUser().getId());
            save(curriculumVitaeBase);
        }
    }


}
